#!/bin/bash
log="$1"
date=$(date -d "8 hour" -u +%Y%m%d)
time=$(date -d "8 hour" -u +%H:%M)
week=$(date -d "-2 days" -u +%Y%m%d)
if grep ${date} ~/app-root/repo/log/update.log; then
  last=$(grep -o "[0-9]\{8\}" ~/app-root/repo/log/update.log| sed -n 2p)
  sed -i -e "/${date}/,/${last}/s#".*"${log}".*"##" -e '/^$/d' ~/app-root/repo/log/update.log
  sed -i "/ ${last} /i\ ${time} ${log}" ~/app-root/repo/log/update.log
else
  last=$(grep -o "[0-9]\{8\}" ~/app-root/repo/log/update.log|head -1)
  sed -i "/ ${last} /i\ ********* ${date} 更新历史 *********" ~/app-root/repo/log/update.log
  sed -i "/ ${last} /i\ ${time} ${log}" ~/app-root/repo/log/update.log
  sed -i '/ '${week}'/,$'d ~/app-root/repo/log/update.log
fi
